package com.wcar.user.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wcar.common.entity.FrontUser;
import com.wcar.common.entity.LoginLog;
import com.wcar.common.entity.Role;
import com.wcar.common.entity.User;
import com.wcar.common.util.OssUtil;
import com.wcar.common.vo.Result;
import com.wcar.user.service.UserService;
import com.wcar.user.service.impl.FrontUserService;
import com.wcar.user.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @program: four-wcar-idea
 * @description:
 * @author: 吴朝阳
 * @create: 2024-05-27 16:35
 **/
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private FrontUserService frontUserService;
    @PostMapping("/api/{currentPage}/{pageSize}")
    public Result<Page<User>> getUser(@PathVariable Integer currentPage, @PathVariable Integer pageSize, @RequestBody UserVo userVo) {
        System.out.println(userVo);
        return userService.getUser(currentPage, pageSize,userVo);

    }
    @PostMapping("/uploadImage")
    public Result<String> uploadImage(MultipartFile file){
        System.out.println("file = " + file);
        String s = OssUtil.uploadOss(file);
        System.out.println("s = " + s);
        return new Result<String>(200,"上传成功",s);
    }
    @PostMapping("add")
    public Result<User> addUser(@RequestBody User user){
        return userService.addUser(user);
    }
    @PostMapping("update")
    public Result<User> updateUser(@RequestBody User user){
        return userService.updateUser(user);
    }
    @PostMapping("delete")
    public Result<User> deleteUser(@RequestBody User user){
        return userService.deleteUser(user);
    }
    @PostMapping("role")
    public Result<Integer> updateRole(Integer userId, List<Integer> roleIds){
        return userService.updateRole(userId,roleIds);
    }
    @PostMapping("/selectAllRole")
    public Result<List<Role>>selectAllRole(){
        return userService.selectAllRole();
    }
    //添加用户登录日志
    @PostMapping("/addLoginLog")
    public Result<Integer> addLoginLog(@RequestBody LoginLog user){
        return userService.addLoginLog(user);
    }
    @PostMapping("api/updateUser")
    public Result<FrontUser> updateUser(@RequestBody FrontUser frontUser){
        return frontUserService.updatefronUser(frontUser);
    }
}
